<?php

declare(strict_types=1);

namespace app\common\model\sys;

use think\Model;
use app\common\traits\ModelTrait;
use think\model\concern\SoftDelete;

/**
 * 系统用户表 (员工表也并一起了) -模型
 * @author:kaige
 * @update:2022-04-25
 * @copyright ©2022 泉州市盛筑信息科技有限公司 版权所有
 */
class SysUser extends Model
{
  use SoftDelete;
  //时间自动存储
  protected $autoWriteTimestamp = true;
  protected $createTime = 'create_time';
  protected $updateTime = 'update_time';
  //软删除位
  protected $deleteTime = 'delete_time';

  // 设置字段信息(避免多一次查询的开销)
  protected $schema = [
    'id'                  => 'int',
    'client_id'           => 'string',
    'bn'                  => 'string',
    'un'                  => 'string',
    'pwd'                 => 'string',
    'e_pwd_n'             => 'int',
    'ln'                  => 'int',
    'status'              => 'int',
    'type'                => 'int',
    'sex'                 => 'int',
    'tel'                 => 'string',
    'avatar'              => 'string',
    'sign'                => 'string',
    'u_friend'            => 'string',
    'dept_id'             => 'int',
    'dept_id_name'        => 'string',
    'dept_other'          => 'string',
    'dept_other_name'     => 'string',
    'dept_path'           => 'string',
    'ranking_id'          => 'string',
    'ranking_id_name'     => 'string',
    'ranking_other'       => 'string',
    'ranking_other_name'  => 'string',
    'super_id'            => 'int',
    'super_name'          => 'string',
    'super_path'          => 'string',
    'group_name'          => 'string',
    'real_name'           => 'string',
    'pingyin_name'        => 'string',
    'email_pwd'           => 'string',
    'company_id'          => 'int',
    'company_d_id'        => 'int',
    'phone'               => 'string',
    'weixin_id'           => 'string',
    'entry_time'          => 'int',
    'dimission_time'      => 'int',
    'theme'               => 'string',
    'is_app_push'         => 'int',
    'last_push_time'      => 'int',
    'online'              => 'int',
    'last_ip'             => 'string',
    'last_time'           => 'int',
    'is_card'             => 'int',
    'sz_salt'             => 'string',
    'on_duty'             => 'int',
    'sort'                => 'int',
    'bankcard'            => 'string',
    'kaihuhang'           => 'string',
    'base'                => 'decimal',
    'create_time'         => 'int',
    'update_time'         => 'int',
    'delete_time'         => 'int',
    'email'               => 'string',
    'contract_code'       => 'string',
    'contract_file'       => 'string',
    'quit_file'           => 'string',
    'is_kq'               => 'int',
    'is_balance'          => 'int',
    'emergency_contact'   => 'string',
    'emergency_phone'     => 'string',
    'is_marry'            => 'int',
    'educational'         => 'string',
    'id_card'             => 'string',
    'id_card_front'           => 'string',
    'id_card_verso'           => 'string',
    'nation'                  => 'string',
    'address'                 => 'string',
    'card_address'            => 'string',
    'politics'                => 'string',
    'educ_img'                => 'string',
    'graduate_institutions'   => 'string',
    'accept_info'             => 'int',
    'message_voice'           => 'int',
  ];

  use ModelTrait;

  public function glcompany()
  {
    return $this->hasOne('app\common\model\hrm\HrmCompany', 'id', 'company_id')->bind(['company_name' => 'name']);
  }

  /**
   * 关联考勤用户设置表
   */
  public function glkquserset()
  {
    return $this->hasOne('app\common\model\hrm\HrmKqUserset', 'user_id', 'id')->bind([
      'is_dk' => 'is_dk',
      'dk_ip' => 'dk_ip',
      'dk_mac' => 'dk_mac'
    ]);
  }

  /**
   * 关联考勤排班用户
   */
  public function glkqpbuser()
  {
    return $this->hasOne('app\common\model\hrm\HrmKqPbuser', 'user_id', 'id')->bind([
      'pbuid' => 'id',
      'mid' => 'mid',
      'user_id' => 'user_id',
      'month' => 'month',
      'pb_1' => 'pb_1',
      'pb_2' => 'pb_2',
      'pb_3' => 'pb_3',
      'pb_4' => 'pb_4',
      'pb_5' => 'pb_5',
      'pb_6' => 'pb_6',
      'pb_7' => 'pb_7',
      'pb_8' => 'pb_8',
      'pb_9' => 'pb_9',
      'pb_10' => 'pb_10',
      'pb_11' => 'pb_11',
      'pb_12' => 'pb_12',
      'pb_13' => 'pb_13',
      'pb_14' => 'pb_14',
      'pb_15' => 'pb_15',
      'pb_16' => 'pb_16',
      'pb_17' => 'pb_17',
      'pb_18' => 'pb_18',
      'pb_19' => 'pb_19',
      'pb_20' => 'pb_20',
      'pb_21' => 'pb_21',
      'pb_22' => 'pb_22',
      'pb_23' => 'pb_23',
      'pb_24' => 'pb_24',
      'pb_25' => 'pb_25',
      'pb_26' => 'pb_26',
      'pb_27' => 'pb_27',
      'pb_28' => 'pb_28',
      'pb_29' => 'pb_29',
      'pb_30' => 'pb_30',
      'pb_31' => 'pb_31'
    ]);
  }
}
